﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMD.DataModel.Entity;
using SmartMD.DataAccess.Service;

namespace SmartMD.Manager.Common
{
    public class CacheUtil
    {
        private static CacheUtil _inst = null;
        private Dictionary<string, DictionaryType> _dictSet = new Dictionary<string, DictionaryType>();

        public CacheUtil()
        {
            
        }
        public static CacheUtil GetInstance()
        {
            if (_inst == null)
            {
                _inst = new CacheUtil();
            }
            return _inst;
        }

        public void Init()
        {
            //将字典缓存内存
             List<DictionaryType> dictTypeList = DataServiceManager.DataDictService.loadAllDictianryInfo();
             if (dictTypeList != null)
             {
                 for (int i = 0; i < dictTypeList.Count; i++)
                 {
                     _dictSet.Add(dictTypeList[i].Name, dictTypeList[i]);
                 }
             }
        }

        public DictionaryType GetDictionaryByName(string name)
        {
            DictionaryType dictType = null;
             foreach(var key in _dictSet)
            {
                if (key.Key == name)
                {
                    dictType = key.Value;
                    break;
                }
            }
             return dictType;
        }
    }
}
